//
// Created by 高森森 on 2022/9/21.
//

#ifndef LEETCODE_SOLUTION_3_H
#define LEETCODE_SOLUTION_3_H
#include<bits/stdc++.h>
using namespace std;

class solution_3 {
public:
    int thirdMax(vector<int>& nums) {
        set<int>maxsize;
        for(int i=0;i<nums.size();i++){
            maxsize.insert(nums[i]);
            if(maxsize.size()>3){
                maxsize.erase(maxsize.begin());
            }
        }

       return maxsize.size()==3?*maxsize.begin():*maxsize.rbegin();
    }
};


#endif //LEETCODE_SOLUTION_3_H
